import br.com.nooclix.salon.ui.util.ResponseData;
import br.com.nooclix.salon.ui.util.WindowsMessage;

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

//Essa parte é executada após salvar no banco!
//Esse código é chamado pela ProductWindow

public function persistResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	//Compara se a resposta do status é igual à mensagem do método .ok()
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Produto salvo com sucesso!");
		clearFields();
		if(bySearch){
			this.currentState = "search";
			findByName();
		}
		
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}

public function removeResult(event:ResultEvent):void{
	var resposeData:ResponseData = event.result as ResponseData;
	
	if(resposeData.status == ResponseData.ok()){
		findByName();
	}else{
		WindowsMessage.alarm(resposeData.message);
	}
}

public function updateResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		WindowsMessage.confirm("Produto atualizado com sucesso!");
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}

public function findByNameResult(event:ResultEvent):void{
	var responseData:ResponseData = event.result as ResponseData;
	
	if(responseData.status == ResponseData.ok()){
		gridProduct.dataProvider = responseData.items;
	}else{
		WindowsMessage.alarm(responseData.message);
	}
}